//
//  BaseWebViewController.swift
//  SwiftDemo
//
//  Created by 宏泰财富 on 2018/11/12.
//  Copyright © 2018 宏泰财富. All rights reserved.
//

import UIKit
import WebKit

class BaseWebViewController: BaseViewController, WKUIDelegate, WKNavigationDelegate, WKScriptMessageHandler {
    
    lazy var progressView: UIProgressView = self.creatProgress()
    lazy var webView: WKWebView = self.creatWebview()
    
    override func viewDidLoad() {
        super.viewDidLoad()
    }
    
    private func creatProgress() -> UIProgressView {
        let progressView: UIProgressView = UIProgressView()
        progressView.progressTintColor = UIColor.yellow
        return progressView
    }
    
    private func creatWebview() -> WKWebView{
        let webView: WKWebView = WKWebView()
        webView.uiDelegate = self
        webView.navigationDelegate = self
        webView.addObserver(self, forKeyPath: "estimatedProgress", options:.new, context: nil)
        return webView
    }
    
    func webView(_ webView: WKWebView, runJavaScriptAlertPanelWithMessage message: String, initiatedByFrame frame: WKFrameInfo, completionHandler: @escaping () -> Void) {
        
    }
    
    func webView(_ webView: WKWebView, runJavaScriptTextInputPanelWithPrompt prompt: String, defaultText: String?, initiatedByFrame frame: WKFrameInfo, completionHandler: @escaping (String?) -> Void) {
        
    }
    
    func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
        
    }
    
    func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
        
    }
    
    
}
